package cn.com.w.web.Factory;

import cn.com.w.common.Emun.Register;
import cn.com.w.dao.Service.Impl.EmailJudgeServiceImpl;
import cn.com.w.dao.Service.Impl.PhoneJudgeServiceImpl;
import cn.com.w.dao.Service.Impl.WeChatJudgeServiceImpl;
import cn.com.w.dao.Service.RegisterJudgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author w
 * @Description:
 * @DateTime: 2025 05 07 19:49
 **/
@Component
public class RegisterJudgeFactory {
    private final Map<Register, RegisterJudgeService> map = new HashMap<>();

    private final EmailJudgeServiceImpl emailJudgeService;
    private final PhoneJudgeServiceImpl phoneJudgeService;
    private final WeChatJudgeServiceImpl weChatJudgeService;

    @Autowired
    private RegisterJudgeFactory(EmailJudgeServiceImpl emailJudgeService,
                                 PhoneJudgeServiceImpl phoneJudgeService,
                                 WeChatJudgeServiceImpl weChatJudgeService) {
        this.emailJudgeService = emailJudgeService;
        this.phoneJudgeService = phoneJudgeService;
        this.weChatJudgeService = weChatJudgeService;
    }

    @PostConstruct
    public void init() {
        map.put(Register.EMAIL, emailJudgeService);
        map.put(Register.PHONE, phoneJudgeService);
        map.put(Register.WECHAT, weChatJudgeService);
    }

    public RegisterJudgeService registerJudge(Register type) {
        return map.get(type);
    }
}